package servlet;

import entity.Jilu;
import service.impl.userserviceImpl;
import service.userservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@WebServlet(urlPatterns = "/addServlet")
public class addServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        String name1 = req.getParameter("state");
        String kahao = req.getParameter("kahao");
        String money = req.getParameter("money");

        userservice u = new userserviceImpl();
        Jilu j = new Jilu();
        j.setFuname(name);
        j.setShouname(name1);
        j.setShoukahao(kahao);
        j.setMoney(money);

        PrintWriter out = resp.getWriter();
        try {
            int i = u.adduser(j);
            if (i > 0) {
                out.print("添加成功");
            }
            out.flush();
            out.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
